/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package controllers;

import java.io.IOException;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import models.Course;
import models.User;
import org.hibernate.Session;
import service.CourseDao;
import service.HibernateUtil;

/**
 *
 * @author Aster
 */
public class LogController extends HttpServlet {

    public void doGet(HttpServletRequest request, HttpServletResponse response)
            throws IOException, ServletException {
        if (request.getParameter("sc") != null) {
            
            Long item = Long.parseLong(request.getParameter("sc"));
            HibernateUtil HU = new HibernateUtil();
            Session sessie = HU.openSession();
            CourseDao cd = new CourseDao(sessie);
            Course course = cd.get(item);
            System.out.println(course);
            HttpSession session = request.getSession(true);
            session.setAttribute("participantsOfCourse", course.getUsers());
            response.sendRedirect("tutorlog.jsp");
            
        } else {
            response.sendRedirect("tutorlog.jsp");
        }
    }

    private void forward(HttpServletRequest request, HttpServletResponse response)
            throws IOException, ServletException {
        String address = "/tutor";
        RequestDispatcher dispatcher = request.getRequestDispatcher(address);
        dispatcher.forward(request, response);
    }
}
